package com.cr.front.base.config;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Slf4j
@Configuration
public class SaTokenConfig {

    @Bean
    public StpInterface stpInterface(){
        return new StpInterface(){
            @Override
            public List<String> getPermissionList(Object o, String s) {
                List<String> perms = (List<String>) StpUtil.getSession().get("perms");
                log.debug("[{}]用户的权限列表:{}",o,perms);
                return perms;
            }

            @Override
            public List<String> getRoleList(Object o, String s) {
                List<String> roles = (List<String>) StpUtil.getSession().get("roles");
                log.debug("[{}]用户的角色列表:{}",o,roles);
                return roles;
            }
        };
    }


}
